package com.gyg.controller;

import com.gyg.domain.CloudUser;
import com.gyg.returns.RespEntity;
import com.gyg.returns.RespTable;
import com.gyg.service.CloudUserService;
import com.gyg.vo.MapVO;
import com.gyg.vo.param.LoginParam;
import com.gyg.vo.param.PageParam;
import com.gyg.vo.param.SearchUserParam;
import com.gyg.vo.result.SexResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author gyg
 * @since 2021-02-20
 */
@RestController
@RequestMapping("/cloud-user")
@Slf4j
@Api(value = "用户模块", tags = "用户模块")
public class CloudUserController {

    @Resource
    private CloudUserService cloudUserService;

    @PostMapping("/login")
    @ApiOperation(value = "用户登陆")
    public RespEntity<CloudUser> login(@RequestBody LoginParam loginParam) {
        RespEntity<CloudUser> respEntity = cloudUserService.login(loginParam);
        return respEntity;
    }

    @GetMapping("/info")
    @ApiOperation(value = "用户信息")
    @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "userId", value = "用户id", required = true)
    public RespEntity<CloudUser> userInfo(@RequestParam(value = "userId", required = true) Integer userId) {
        RespEntity<CloudUser> respEntity = cloudUserService.userInfo(userId);
        return respEntity;
    }

    @GetMapping("/list")
    @ApiOperation(value = "用户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "limit", value = "每页数量", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "column", value = "字段名", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "limit", value = "字段值", required = false)
    })
    public RespTable<List<CloudUser>> cloudUserList(@RequestParam(value = "page", required = true) Integer page,
                                                    @RequestParam(value = "limit", required = true) Integer limit,
                                                    @RequestParam(value = "column", required = false) String column,
                                                    @RequestParam(value = "value", required = false) String value) {
        RespTable<List<CloudUser>> respTable = cloudUserService.cloudUserList(page, limit, column, value);
        return respTable;
    }

    @PutMapping("/ban")
    @ApiOperation(value = "封禁用户")
    @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "userId", value = "用户id", required = true)
    public RespEntity cloudUserBan(@RequestParam(value = "userId", required = true) Integer userId) {
        RespEntity respEntity = cloudUserService.cloudUserBan(userId);
        return respEntity;
    }

    @PutMapping("/deBlock")
    @ApiOperation(value = "解封用户")
    @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "userId", value = "用户id", required = true)
    public RespEntity cloudUserDeBlock(@RequestParam(value = "userId", required = true) Integer userId) {
        RespEntity respEntity = cloudUserService.cloudUserDeBlock(userId);
        return respEntity;
    }

    @GetMapping("/banList")
    @ApiOperation(value = "用户黑名单")
    public RespTable cloudUserBanList(PageParam pageParam) {
        RespTable respTable = cloudUserService.cloudUserBanList(pageParam);
        return respTable;
    }

    @GetMapping("/ids")
    @ApiOperation(value = "按照ids查询用户")
    @ApiImplicitParam(paramType = "query", dataType = "Integer[]", name = "ids", value = "用户ids")
    public RespEntity<List<CloudUser>> queryUserByIds(@RequestParam("ids") Integer[] ids) {
        RespEntity<List<CloudUser>> respEntity = cloudUserService.queryUserByIds(ids);
        return respEntity;
    }

    @GetMapping("/all")
    @ApiOperation(value = "查询全部用户")
    public RespEntity<List<CloudUser>> queryAllUser() {
        RespEntity<List<CloudUser>> respEntity = cloudUserService.queryAllUser();
        return respEntity;
    }

    @GetMapping("/sex")
    @ApiOperation(value = "用户性别统计")
    public RespEntity<SexResult> sexCount() {
        RespEntity<SexResult> respEntity = cloudUserService.querySexCount();
        return respEntity;
    }

    @GetMapping("/chinaMap")
    @ApiOperation(value = "中国地图")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "beginDate", value = "开始时间", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "endDate", value = "结束时间", required = false),
    })
    public RespEntity<List<MapVO>> chinaMap(@RequestParam(value = "beginDate", required = false) String beginDate,
                                            @RequestParam(value = "endDate", required = false) String endDate) {
        RespEntity<List<MapVO>> respEntity = cloudUserService.chinaMap(beginDate, endDate);
        return respEntity;
    }

    @GetMapping("/provinceMap")
    @ApiOperation(value = "省份地图")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "province", value = "省份名称", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "beginDate", value = "开始时间", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "endDate", value = "结束时间", required = false),
    })
    public RespEntity<List<MapVO>> provinceMap(@RequestParam(value = "province", required = true) String province,
                                               @RequestParam(value = "beginDate", required = false) String beginDate,
                                               @RequestParam(value = "endDate", required = false) String endDate) {
        RespEntity<List<MapVO>> respEntity = cloudUserService.provinceMap(province, beginDate, endDate);
        return respEntity;
    }

}
